package estore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ProductService3 {
    private final Map<String, Product3> productData = new HashMap<>();

    public ProductService3() {
        // 创建标签集合
        Set<String> javaBookTags = new HashSet<>();
        javaBookTags.add("编程");
        javaBookTags.add("畅销");
        javaBookTags.add("热门");
        javaBookTags.add("热门"); // 测试重复标签

        Set<String> mysqlBookTags = new HashSet<>();
        mysqlBookTags.add("数据库");
        mysqlBookTags.add("技术");

        Set<String> healthBookTags = new HashSet<>();
        healthBookTags.add("健康");
        healthBookTags.add("生活");
        healthBookTags.add("畅销");

        // 初始化商品数据
        productData.put("p001", new Product3("p001", "Java从入门到精通", 99.0, 100, javaBookTags));
        productData.put("p002", new Product3("p002", "高性能MySQL", 128.5, 50, mysqlBookTags));
        productData.put("p003", new Product3("p003", "颈椎康复指南", 45.0, 200, healthBookTags));
        productData.put("p004", new Product3("p004", "生发秘籍", 88.0, 0)); // 无标签商品
    }

    public List<Product3> getAllProducts() {
        return new ArrayList<>(productData.values());
    }

    public Product3 findProductById(String id) {
        return productData.get(id);
    }
}